﻿--获得本单位岗位异动人员数据
CREATE PROCEDURE [dbo].[proc_Employee_PostMove_GetList_Count]
(
		@CompanyId int,
		@DepId int,
		@Stext nvarchar(50)

)
as
begin
declare @indextable table(id int identity(1,1),nid int)
	;WITH ChildDepartment(ID,DName,PId) AS
	(
		SELECT ID,DName,ParentID FROM department WHERE id=@DepId
	    
		UNION ALL
		SELECT department.ID,department.DName,department.ParentID FROM ChildDepartment AS d
		INNER JOIN department ON d.ID = department.ParentID
	)
	
	insert into @indextable(nid) select Id from ChildDepartment;
	
	Select count(id) from Employee_PostMove  ep
	Where 
		(@CompanyId=0 Or ep.BCompanyId=@CompanyId)
		and (@DepId=0 Or  ep.BDepartmentId in(select c.nid from @indextable c))
		and (@Stext='' Or ep.Ename like '%'+@Stext+'%')
	

end
	RETURN
